package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.EsLendFormProduct;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EsLendForm;
import com.ruoyi.system.service.IEsLendFormService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品借出单(es_lend_form)Controller
 *
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/system/form")
public class EsLendFormController extends BaseController
{
    @Autowired
    private IEsLendFormService esLendFormService;

    /**
     * 查询商品借出单(es_lend_form)列表
     */
    @PreAuthorize("@ss.hasPermi('system:form:list')")
    @GetMapping("/list")
    public TableDataInfo list(EsLendForm esLendForm)
    {
        startPage();
        List<EsLendForm> list = esLendFormService.selectEsLendFormList(esLendForm);
        return getDataTable(list);
    }

    /**
     * 导出商品借出单(es_lend_form)列表
     */
    @PreAuthorize("@ss.hasPermi('system:form:export')")
    @Log(title = "商品借出单(es_lend_form)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EsLendForm esLendForm)
    {
        List<EsLendForm> list = esLendFormService.selectEsLendFormList(esLendForm);
        ExcelUtil<EsLendForm> util = new ExcelUtil<EsLendForm>(EsLendForm.class);
        util.exportExcel(response, list, "商品借出单(es_lend_form)数据");
    }

    /**
     * 获取商品借出单(es_lend_form)详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:form:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(esLendFormService.selectEsLendFormById(id));
    }

    /**
     * 新增商品借出单(es_lend_form)
     */
    @PreAuthorize("@ss.hasPermi('system:form:add')")
    @Log(title = "商品借出单(es_lend_form)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EsLendForm esLendForm)
    {
        return toAjax(esLendFormService.insertEsLendForm(esLendForm));
    }

    /**
     * 修改商品借出单(es_lend_form)
     */
    @PreAuthorize("@ss.hasPermi('system:form:edit')")
    @Log(title = "商品借出单(es_lend_form)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EsLendForm esLendForm)
    {
        return toAjax(esLendFormService.updateEsLendForm(esLendForm));
    }

    /**
     * 删除商品借出单(es_lend_form)
     */
    @PreAuthorize("@ss.hasPermi('system:form:remove')")
    @Log(title = "商品借出单(es_lend_form)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(esLendFormService.deleteEsLendFormByIds(ids));
    }

    /**
     * 确认商品借出单
     */
    @PreAuthorize("@ss.hasPermi('system:form:confirm')")
    @Log(title = "商品借出单(es_lend_form)", businessType = BusinessType.UPDATE)
    @PutMapping("/confirm/{id}")
    public AjaxResult confirm(@PathVariable Long id) {
        return toAjax(esLendFormService.confirmEsLendForm(id));
    }

    /**
     * 归还商品借出单
     */
    @PreAuthorize("@ss.hasPermi('system:form:return')")
    @Log(title = "商品借出单(es_lend_form)", businessType = BusinessType.UPDATE)
    @PutMapping("/return/{id}")
    public AjaxResult returnForm(@PathVariable Long id) {
        return toAjax(esLendFormService.returnEsLendForm(id));
    }

    @PreAuthorize("@ss.hasPermi('system:form:list')")
    @GetMapping("/availableProducts")
    public TableDataInfo listAvailableProducts(EsLendFormProduct product) {
        startPage();
        List<EsLendFormProduct> list = esLendFormService.selectAvailableProducts(product);
        return getDataTable(list);
    }
}
